package multithreading;

/**
 * 三个窗口买票，100张
 *
 * @author DuJiabao
 * @create 2020-12-13 17:51
 */
public class SaleTicket {
    public static void main(String[] args) {
        Windows win1 = new Windows();
        Windows win2 = new Windows();
        Windows win3 = new Windows();

        win1.start();
        win2.start();
        win3.start();
    }

}


class Windows extends Thread {
    private static int total = 100;
//    private static Object object = new Object();

    @Override
    public void run() {
        super.run();
        while (true) {
            synchronized (Windows.class) { //当前类，也是唯一的对象
                if (total <= 0)
                    break;
                System.out.println(Thread.currentThread().getName() + ": " + total--);
            }
        }
    }
}
